<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>系统界面</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="./js/jquery.js" type="text/javascript"></script>
<script src="./js/miniui/miniui.js" type="text/javascript"></script>
<link href="./js/miniui/themes/default/miniui.css" rel="stylesheet"
	type="text/css" />
<link href="./js/miniui/themes/icons.css" rel="stylesheet"
	type="text/css" />
<style type="text/css">
html,body {
	padding: 0;
	border: 0;
	margin: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
	font-size: 12px;
	line-height: 22px;
}
</style>
</head>
<body>
	<div id="datagrid1" class="mini-datagrid"
		style="width: 800px; height: 500px;"
		url="./admin.php?a=Privilege&m=ls" sizeList="[20,50,100]"
		pageSize="20" idField="name">
		<div property="columns">
			<div field="name" width="100" headerAlign="center">
				名称<input property="editor" class="mini-textbox" />
			</div>
			<div field="privilege" width="550" headerAlign="center"
				renderer="onprivilege">
				权限<input property="editor" class="mini-treeselect"
					url="./admin.php?a=Action&m=tree" valueField="id" textField="text"
					multiSelect="true" style="width: 550px;" />
			</div>
			<div field="auth" width="80" renderer="onauth" headerAlign="center"
				align="center">
				验证<input property="editor" class="mini-combobox"
					style="width: 100%;" value="status" data="Auth" />
			</div>
			<div width="50" headerAlign="center" align="center"
				renderer="onhandle">
				<a href="javascript:newRow()"><img src="images/add.gif" /></a>
			</div>
		</div>
	</div>
	<script>
		mini.parse();
		var grid = mini.get("datagrid1");
		grid.load();
		var Auth = [ {
			id : 'yes',
			text : '需要'
		}, {
			id : 'no',
			text : '不需要'
		} ];
		function onauth(e) {
			for ( var i = 0, l = Auth.length; i < l; i++) {
				var g = Auth[i];
				if (g.id == e.value)
					return g.text;
			}
			return "";
		}
		function onprivilege(e) {
			return e.value.replace(/::__FULL__/g, '');
		}
		function onhandle(e) {
			var record = e.record
			var uid = record._uid;
			var s = '<a class="Edit_Button" href="javascript:editRow(\'' + uid
					+ '\')"><img src="images/edit.gif"></a>'
					+ ' <a class="Edit_Button" href="javascript:delRow(\''
					+ uid + '\')"><img src="images/remove.gif"></a>';

			if (grid.isEditingRow(record)) {
				s = '<a class="Update_Button" href="javascript:updateRow(\''
						+ uid
						+ '\')"><img src="images/ok.png"></a> '
						+ '<a class="Cancel_Button" href="javascript:cancelRow(\''
						+ uid + '\')"><img src="images/no.png"></a>'
			}
			return s;
		}
		function newRow() {
			var row = {};
			grid.addRow(row, 0);
			grid.cancelEdit();
			grid.beginEditRow(row);
		}
		function editRow(uid) {
			var row = grid.getRowByUID(uid);
			if (row) {
				grid.cancelEdit();
				grid.beginEditRow(row);
			}
		}
		function cancelRow(row_uid) {
			grid.reload();
		}
		function delRow(row_uid) {
			var row = grid.getRowByUID(row_uid);
			if (row) {
				if (confirm("确定删除此记录？")) {
					grid.loading("删除中，请稍后......");
					$.post('./admin.php?a=Privilege&m=remove', {
						id : row.id
					}, function(text) {
						grid.reload();
					});
				}
			}
		}
		function updateRow(row_uid) {
			var row = grid.getRowByUID(row_uid);
			var rowData = grid.getEditRowData(row);
			grid.loading("保存中，请稍后......");
			var json = mini.encode([ rowData ]);
			$.post('./admin.php?a=Privilege&m=save', {
				info : json
			}, function(text) {
				grid.reload();
			});
		}
	</script>
</body>
</html>